<template>
  <div class="login_container">
    <div class="login-header">
      <div class="header-logo">
        <img src="../assets/images/login_icon.png" alt="login_icon" />
        微信小程序商家管理平台
      </div>
    </div>
    <div class="login-center">
      <div class="login-left">
          <div class="left-cha">
            <img
              src="../assets/images/chahua.png"
              alt=""
              style="width: 100%;height: 100%;"
            />
          </div>
          <div class="left-top">
            <img
              src="../assets/images/top.png"
              alt=""
              style="width: 100%;height: 100%;"
            />
          </div>
          <div class="left-dot">
            <div class="dot-img"></div>
            <div class="dot-img" style="margin-top: 70px;"></div>
          </div>
      </div>
      <div class="login-right">
        <div class="login-bg">
          <div class="right-dot">
            <div class="right-dot-img"></div>
            <div class="right-dot-img" style="margin-top: 140px;"></div>
          </div>
          <div class="login-block">
            <span class="login-title">欢迎登录</span>
            <el-form
              :model="loginForm"
              :rules="loginFormRules"
              ref="loginFormRef"
              label-width="0px"
              class="ruleForm"
            >
              <el-form-item
                label
                prop="username"
              >
                <el-input
                  v-model="loginForm.username"
                  placeholder="请输入账号"
                  clearable
                  prefix-icon="iconfont icon-user"
                >
                </el-input>
              </el-form-item>
              <el-form-item label prop="password">
                <el-input
                  v-model="loginForm.password"
                  placeholder="请输入密码"
                  type="password"
                  clearable
                  prefix-icon="iconfont icon-password"
                >
                </el-input>
              </el-form-item>
              <el-form-item class="el-form-item-login">
                <el-button
                  class="submit-btn"
                  type="primary"
                  @click="login()"
                  >登 录</el-button
                >
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
    </div>
    <div class="login-footer">
      建议使用1366*768分辨率/IE9.0或以上浏览器访问达到最佳效果
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      /* 这是登录表单数据绑定对象 */
      loginForm: {
        username: 'yjx',
        password: '123456'
      },
      /* 这是表单的验证规则 */
      loginFormRules: {
        username: [
          { required: true, message: '请输入用户名称', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入用户密码', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 点击重置按钮，重置表单
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields()
    },
    login() {
      this.$refs.loginFormRef.validate(async valid => {
        if (!valid) return
        const { data: res } = await this.$http.post('login', this.loginForm)
        if (res.meta.status != 200) return this.$message.error('登录失败！')
        this.$message.success('登录成功！')
        var storage=window.localStorage;
        storage["username"]=res.data.username;
        storage["business_id"]=res.data.id;
        window.sessionStorage.setItem('token', res.data.token)
        this.$router.push('/home')
      })
    }
  }
}
</script>

<style lang="less" scoped>
// scoped表示只在当前组件下生效
.login_container {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url('../assets/images/login.png');
  background-repeat: no-repeat;
  background-size: cover;
}
.login_text {
  height: 50px;
  padding-left: 24px;
  font-size: 16px;
  line-height: 50px;
  color: white;
}
.login-header {
  position: absolute;
  top: 0;
  width: 100%;
  height: 50px !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #28a0ba;
  .header-logo {
    display: flex;
    align-items: center;
    height: 30px;
    cursor: pointer;
    margin-right: 50px;
    font-family: "STKaiti";
    font-weight: 600;
    font-size: 20px;
    letter-spacing: 3px;
    color: #fff;
    img {
      height: 100%;
      background-repeat: no-repeat;
      background-position: left center;
      margin: 0 5px 0 20px;
    }
  }
}
.login-center {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .login-left {
    width: 35%;
    position: relative;
    display: flex;
    justify-items: center;
    align-items: center;
    transform: translateY(-8px) translateX(16px);
    .left-cha {
      width: 100%;
    }
    .left-top {
      width: 180px;
      position: absolute;
      top: 10%;
      right: 30%;
      animation: move_top 5s ease infinite;
    }
    .left-dot {
      width: 60px;
      height: 70px;
      position: absolute;
      top: 5%;
      left: 52%;
      overflow: hidden;
      animation: move_top 5s ease infinite;
    }
    .dot-img {
      width: 100%;
      height: 70%;
      top: 0;
      position: absolute;
      background-image: url("../assets/images/float-dot.png");
      background-size: 100% 100%;
      animation: move_arrow 0.4s linear infinite;
    }
    @keyframes move_arrow {
      from {
        transform: translateY(0);
      }
      to {
        transform: translateY(-70px);
      }
    }
    @keyframes move_top {
      0% {
        transform: translateY(0);
      }
      50% {
        transform: translateY(-30px);
      }
      100% {
        transform: translateY(0);
      }
    }
  }
  .login-right {
    width: 30%;
    margin-left: 5%;
    box-sizing: border-box;
    // transform: translateY(-8px) translateX(-8px);
    .login-bg {
      padding: 18% 0 10px 0;
      box-sizing: border-box;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      .right-dot {
        width: 82%;
        height: 50%;
        position: absolute;
        top: -4%;
        // z-index: -1;
        overflow: hidden;
      }
      .right-dot-img {
        width: 100%;
        height: 70%;
        top: 0;
        position: absolute;
        background-image: url("../assets/images/float-dot2.png");
        background-size: 100% 100%;
        animation: move_dot 1.2s linear infinite;
        /*border: 1px solid pink;*/
      }
      @keyframes move_dot {
        from {
          transform: translateY(0);
        }
        to {
          transform: translateY(-140px);
        }
      }
      .login-block {
        width: 64%;
        background-image: linear-gradient(
          to bottom,
          rgb(57, 75, 105),
          rgb(38, 49, 69)
        );
        padding: 6.5% 5% 9% 5%;
        box-sizing: border-box;
      }
      .login-title {
        font-size: 16px;
        color: #fff;
      }
      .ruleForm {
        margin-top: 10%;
      }
      .el-form-item-pwdOperate {
        margin-top: 18%;
        margin-bottom: 3%;
      }
    }
    .other-login {
      padding: 0 0 14% 0;
      width: 64%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #ffffff;
      line-height: unset;
      .el-form-item__content {
        line-height: unset;
      }
      img {
        display: inline-block;
        width: 25px;
        height: 25px;
        margin-right: 10px;
        cursor: pointer;
      }
    }
  }
}
.login-footer {
  color: #fff;
  opacity: 0.8;
  position: absolute;
  left: 40%;
  bottom: 40px;
  font-size: 12px;
}
.login_box {
  width: 400px;
  height: 300px;
  background: #2f3d56;
  border-radius: 3px;
  position: absolute;
  left: 75%;
  top: 50%;
  transform: translate(-50%, -50%);
  .avatar_box {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    height: 100px;
    width: 100px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 3px;
    box-shadow: 0 0 3px #ddd;
    background-color: #fff;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
}
/deep/ .submit-btn {
  width: 100%;
  height: 48px;
  border-radius: 1px;
  background-image: linear-gradient(to right, #00b8fd, #008bff);
}
/deep/ .el-input__inner {
  color: #fff;
  background-color: #232f42;
  border: none;
}
</style>
